const loopback = require('loopback');
const boot = require('loopback-boot');
const path = require('path');
const { batchDisableRemoteMethod } = require('../common/utils/tool.ts');

const app = (module.exports = loopback());

app.start = function () {
  console.log('__dirname', __dirname, __filename);
  // start the web server
  return app.listen(function () {
    app.emit('started');
    const baseUrl = app.get('url').replace(/\/$/, '');
    console.log('Web server listening at: %s', baseUrl);
    if (app.get('loopback-component-explorer')) {
      const explorerPath = app.get('loopback-component-explorer').mountPath;
      console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
    }
  });
};

// 自定义路由配置，通过访问http://localhost:3000/test
app.use('/test', require(path.resolve(__dirname, './routes/router.js')).router);

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function (err) {
  if (err) throw err;

  // start the server if `$ node server.js`
  if (require.main === module) app.start();
});
